package com.six666.medicaldevicetestingsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six666.medicaldevicetestingsystem.dto.Order_DTO;
import com.six666.medicaldevicetestingsystem.entity.GoodsList;
import com.six666.medicaldevicetestingsystem.mapper.GoodsList_Mapper;
import com.six666.medicaldevicetestingsystem.service.GoodsList_Service;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsList_Service_Impl extends ServiceImpl<GoodsList_Mapper, GoodsList> implements GoodsList_Service{
    @Override
    public boolean add_good_list(int order_id, int goods_id,String order_type, int goods_amount) {
        try {
            GoodsList gl=new GoodsList(order_id,goods_id,order_type,goods_amount);
            save(gl);
        }
        catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public List<Order_DTO> get_good_list(int order_id) {
        return List.of();
    }

    @Override
    public boolean delete_good_list(int order_id) {
        QueryWrapper<GoodsList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderid",order_id);
        return remove(queryWrapper);
    }

    @Override
    public boolean change_goods_amount(int order_id, int goods_id, int goods_amount) {
        if (goods_amount<1)return false;
        UpdateWrapper<GoodsList> updatewrapper = new UpdateWrapper<>();
        updatewrapper.eq("orderid",order_id);
        updatewrapper.eq("goodsid",goods_id);
        updatewrapper.set("goodsamount",goods_amount);
        return update(updatewrapper);
    }

    @Override
    public List<GoodsList> get_goods_list(int order_id) {
        QueryWrapper<GoodsList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderid",order_id);
        return list(queryWrapper);
    }

    @Override
    public boolean delete_good(int order_id, int good_id) {
        QueryWrapper<GoodsList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderid",order_id);
        queryWrapper.eq("goodsid",good_id);
        return remove(queryWrapper);
    }
}
